package com.wh.accesscontrol.util;

import java.io.*;
import java.util.Date;


public class LogUtil {


    public static void input(String fileName, String str) {

        Date now = new Date();
        String dateStr = DateUtil.dateToString("yyyy-MM-dd", now);
        //String path = PropUtil.getValue("config.properties", "logFilePath")
                String path="./storage/logs"
                + File.separator
                + dateStr
                + "----"
                + fileName + ".txt";
        File file = new File(path);
        if (!file.exists()) {
            try {
                file.createNewFile(); // 创建文件
            } catch (IOException e) {
                System.out.println("**创建文件失败**");
                return;
            }
        }

        BufferedWriter out = null;
        dateStr = DateUtil.dateToString("yyyy-MM-dd HH:mm:ss", now);
        try {
            out = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(file, true)));
            out.write(dateStr + " " + "\r\n" + str + "\r\n" );
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("**写入文件失败**");
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
